package com.yxy.utils;

import com.alibaba.druid.pool.DruidDataSource;

import java.sql.*;
import java.util.LinkedList;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @Author 杨芯叶
 * @Create 2025-07-24-10:10
 * @Message
 **/
public class DatabasePollUtil {

    public final static DruidDataSource dataSource = new DruidDataSource();

    static {
        try {
            dataSource.setUsername("root");
            dataSource.setPassword("iwebyxy");
            dataSource.setUrl("jdbc:mysql://127.0.0.1:3306/yxy?useUnicode=true");
            dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
            dataSource.init();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static Connection connect() {
        Connection conn = null;
        try {
            conn = dataSource.getConnection();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return conn;
    }
}